package com.goldgov.interfacemanage.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.goldgov.interfacemanage.dao.InterfaceManageDao;
import com.goldgov.interfacemanage.service.InterfaceManage;
import com.goldgov.interfacemanage.service.InterfaceManageQuery;
import com.goldgov.interfacemanage.service.InterfaceManageService;
import com.goldgov.interfacemanage.service.InterfaceParam;

/** 
 * @ClassName: InterfaceManageServiceImpl 
 * @Description: 接口服务类
 * @author hanxiangyu
 * @date 2018年7月23日 下午3:33:21 
 */
@Service
public class InterfaceManageServiceImpl implements InterfaceManageService {

	@Autowired
	private InterfaceManageDao interfaceManageDao;
	
	
	@Override
	public Boolean addInterfaceManage(InterfaceManage interfaceManage) {
		Boolean fase = false;
		int state = interfaceManageDao.addInterfaceManage(interfaceManage);
		if (interfaceManage.getInterfaceParam() != null) {
			for (InterfaceParam interfaceParam : interfaceManage.getInterfaceParam()) {
				interfaceParam.setInterfaceParamID(interfaceManageDao.preAdd());
				interfaceParam.setInterfaceID(interfaceManage.getInterfaceID());
			}
			state = interfaceManageDao.addInterfaceParams(interfaceManage.getInterfaceParam());
		}
		if (state > 0) {
			fase = true;
		}
		return fase;
	}

	@Override
	public Boolean deleteInterfaceManage(String[] ids) {
		Boolean fase = false;
		int state = interfaceManageDao.deleteInterfaceManage(ids);
		if (state > 0) {
			fase = true;
		}
		return fase;
	}

	@Override
	public Boolean updateInterfaceManage(InterfaceManage interfaceManage) {
		Boolean fase = false;
		int state = interfaceManageDao.updateInterfaceManage(interfaceManage);
		if (state > 0) {
			String[] ids = {interfaceManage.getInterfaceID()};
			interfaceManageDao.deleteInterfaceParams(ids);
			if (interfaceManage.getInterfaceParam() != null) {
				for (InterfaceParam interfaceParam : interfaceManage.getInterfaceParam()) {
					interfaceParam.setInterfaceParamID(interfaceManageDao.preAdd());
					interfaceParam.setInterfaceID(interfaceManage.getInterfaceID());
				}
				state = interfaceManageDao.addInterfaceParams(interfaceManage.getInterfaceParam());
			}
			fase = true;
		}
		return fase;
	}

	@Override
	public List<InterfaceManage> getInterfaceManageList(InterfaceManageQuery query) {
		return interfaceManageDao.getInterfaceManageList(query);
	}

	@Override
	public String preAdd() {
		return interfaceManageDao.preAdd();
	}

	@Override
	public InterfaceManage getInterfaceById(String id) {
		return interfaceManageDao.getInterfaceById(id);
	}

	@Override
	public Boolean addInterfaceParam(InterfaceParam interfaceParam) {
		Boolean fase = false;
		int state = interfaceManageDao.addInterfaceParam(interfaceParam);
		if (state > 0) {
			fase = true;
		}
		return fase;
	}
}
